package com.spzx.product.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.spzx.common.core.web.controller.BaseController;
import com.spzx.common.core.web.domain.AjaxResult;
import com.spzx.common.core.web.page.TableDataInfo;
import com.spzx.common.security.utils.SecurityUtils;
import com.spzx.product.domain.Brand;
import com.spzx.product.domain.CategoryBrand;
import com.spzx.product.service.CategoryBrandService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;

/**
 * @ClassName CategoryBrandController
 * @Author 波
 * @Date 2024/7/29 19:02
 */
@RestController
@RequestMapping("/categoryBrand")
@Tag(name = "分类品牌接口管理")
public class CategoryBrandController extends BaseController {
    @Resource
    private CategoryBrandService categoryBrandService;

    @Operation(summary = "根据分类ID查询品牌列表")
    @GetMapping("/brandList/{categoryId}")
    public AjaxResult getBrandListByCategoryId(@PathVariable Long categoryId) {
        List<Brand> brandList = categoryBrandService.getBrandListByCategoryId(categoryId);
        return success(brandList);
    }


    @Operation(summary = "查询分类品牌分页列表")
    @GetMapping("/list")
    public TableDataInfo list(CategoryBrand categoryBrand) {
        startPage();
        List<CategoryBrand> categoryBrandList = categoryBrandService.selectCategoryBrandList(categoryBrand);
        return getDataTable(categoryBrandList);
    }

    @Operation(summary = "获取分类品牌详细信息")
    @GetMapping(value = "/{id}")
    public AjaxResult getCategoryBrandDetailInfo(@PathVariable Integer id) {
        CategoryBrand categoryBrand = categoryBrandService.selectCategoryBrandById(id);
        return success(categoryBrand);
    }

    @Operation(summary = "新增分类品牌")
    @PostMapping
    public AjaxResult addCategoryBrand(@RequestBody @Validated CategoryBrand categoryBrand) {
        categoryBrand.setCreateBy(SecurityUtils.getUsername());
        return toAjax(categoryBrandService.insertCategoryBrand(categoryBrand));
    }

    @Operation(summary = "修改分类品牌")
    @PutMapping
    public AjaxResult updateCategoryBrand(@RequestBody @Validated CategoryBrand categoryBrand) {
        categoryBrand.setUpdateBy(SecurityUtils.getUsername());
        return toAjax(categoryBrandService.updateCategoryBrand(categoryBrand));
    }

    @Operation(summary = "删除分类品牌")
    @DeleteMapping("/{ids}")
    public AjaxResult deleteCategoryBrand(@PathVariable Integer[] ids) {
        return toAjax(categoryBrandService.removeBatchByIds(Arrays.asList(ids)));
    }

}
